package com.wxy.demo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@EnableScheduling
@EnableAsync
@SpringBootApplication
@Slf4j
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    /**
     * 测试corn表达式通过变量传入
     */
    @Scheduled(cron = "${cron.task1}")
    public void task1() {
        log.info("task1 = {}", Thread.currentThread().getName());
    }

    /**
     * 测试调度是否使用线程池
     */
    @Scheduled(fixedRate = 1000)
    @Async
    public void task2() {
        log.info("task2 = {}", Thread.currentThread().getName());
    }

    @Scheduled(fixedRate = 1000)
    @Async
    public void task3() {
        log.info("task3 = {}", Thread.currentThread().getName());
    }

}
